use core::{ptr::null, sync::atomic::AtomicBool};

/// 链表头
#[derive(Debug)]
#[repr(C)]
pub(crate) struct LinkList {
    pub first: BlockLink,    // 第一个节点
    pub end: *mut BlockLink, // 指向的最后一个节点的指针
    pub lock: AtomicBool,    // 用来多线程操作
}

impl LinkList {
    pub const fn new() -> Self {
        Self {
            first: BlockLink {
                next_free: null::<BlockLink>() as _,
                size: 0,
            },
            end: null::<BlockLink>() as _,
            lock: AtomicBool::new(false),
        }
    }
}

unsafe impl Send for LinkList {}
unsafe impl Sync for LinkList {}

/// 链表的节点
#[derive(Debug)]
#[repr(C)]
pub(crate) struct BlockLink {
    pub next_free: *mut BlockLink,
    pub size: usize,
}

pub(crate) static mut LIST: LinkList = LinkList::new();
